package com.dindang.propertyfee.app.utils;

import android.content.Context;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;

import com.longxi.gamer_base.R;

/**
 * Created by cxw on & 2018/8/14
 */
public class TextViewUtils {

    public static SpannableString getKeywordContainsShowColor(Context context, String value, String keyword){
        int start = value.indexOf(keyword);
        int end = start + keyword.length();
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(context.getResources().getColor(R.color.tv_color12));
        SpannableString spannableString = new SpannableString(value);
        spannableString.setSpan(colorSpan, start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    public static SpannableString getPayPrice(String price){
        SpannableString spannableString = new SpannableString("支付金额: ￥" + price);
        RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.5f);
        spannableString.setSpan(sizeSpan, 5, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    public static SpannableString getPayTotalPrice(String price){
        SpannableString spannableString = new SpannableString("￥" + price);
        RelativeSizeSpan sizeSpan = new RelativeSizeSpan(2f);
        spannableString.setSpan(sizeSpan, 1, spannableString.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    /**
     * 倒计时前红
     * @return
     */
    public static SpannableString getRedCountDown(Context context, String countDown){
        SpannableString spannableString = new SpannableString(countDown);
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(context.getResources().getColor(R.color.tv_color12));
        spannableString.setSpan(colorSpan, 0, 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    /**
     * 已成功收款
     * @return
     */
    public static SpannableString getPaymentSuccessPrice(Context context, String price){
        SpannableString spannableString = new SpannableString("已成功收款 " + price);
        RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.125f);
        spannableString.setSpan(sizeSpan, 5, spannableString.length()-1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    /**
     * 已成功收款
     * @return
     */
    public static SpannableString getPaymentSuccessPrice(Context context, String num, String unit){
        SpannableString spannableString = new SpannableString(num + " " + unit);
        RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.4f);
        spannableString.setSpan(sizeSpan, 0, num.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(context.getResources().getColor(R.color.color_text7));
        spannableString.setSpan(colorSpan, 0, num.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    public static SpannableString getPaymentDetailsPrice(double price){
        String sPrice = String.format("%.2f", price);
        SpannableString spannableString = new SpannableString("￥ "+ sPrice + " 元");
        RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.7f);
        spannableString.setSpan(sizeSpan, 1, spannableString.length() - 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    public static SpannableString getPaymentDetailsPrice2(double price){
        String sPrice = String.format("%.2f", price);
        SpannableString spannableString = new SpannableString("合计金额: ￥" + sPrice + "元");
        RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.5f);
        spannableString.setSpan(sizeSpan, 7, spannableString.length() - 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    public static String getPaymentDetailsPrice3(double price){
        String sPrice = String.format("%.2f", price);
        return sPrice;
    }

    public static SpannableString getOverdueAmount(double price){
        String sPrice = String.format("%.2f", price);
        SpannableString spannableString = new SpannableString("￥" + sPrice + "元");
        RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.66f);
        spannableString.setSpan(sizeSpan, 1, spannableString.length() - 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    public static SpannableString getOverdueFamily(String familyTotal){
        SpannableString spannableString = new SpannableString(familyTotal + " 户");
        RelativeSizeSpan sizeSpan = new RelativeSizeSpan(2f);
        spannableString.setSpan(sizeSpan, 0, familyTotal.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    public static String getAmount(double price){
        String sPrice = String.format("%.2f", price);
        return sPrice + "元";
    }

    public static String getAmount2(double price){
        String sPrice = String.format("%.2f", price);
        return "￥" + sPrice;
    }

    public static String getAmount3(double price){
        String sPrice = String.format("%.2f", price);
        return "￥" + sPrice + "元";
    }

    public static SpannableString getAmount3(String total, double amount){

        String sPrice = String.format("%.2f", amount);
        String totalString = "共 " + total + " 笔";
        String priceString = "， 合计: ￥" + sPrice + " 元";
        SpannableString spannableString = new SpannableString(totalString + priceString);
        RelativeSizeSpan sizeSpan2 = new RelativeSizeSpan(1.2f);
        spannableString.setSpan(sizeSpan2, totalString.length() + 7, spannableString.length() - 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    public static SpannableString setFeeHJ(Context context, int total, double sumAmount){
        String sPrice = String.format("%.2f", sumAmount);
        String totalString = "共 " + total + " 户";
        String priceString = "， 合计: ￥" + sPrice + " 元";
        SpannableString spannableString = new SpannableString(totalString + priceString);
        RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.2f);
        spannableString.setSpan(sizeSpan, 2, totalString.length() - 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        RelativeSizeSpan sizeSpan2 = new RelativeSizeSpan(1.2f);
        spannableString.setSpan(sizeSpan2, totalString.length() + 7, spannableString.length() - 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

        ForegroundColorSpan colorSpan = new ForegroundColorSpan(context.getResources().getColor(R.color.tv_color12));
        spannableString.setSpan(colorSpan, 2, totalString.length() - 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        ForegroundColorSpan colorSpan2 = new ForegroundColorSpan(context.getResources().getColor(R.color.tv_color12));
        spannableString.setSpan(colorSpan2, totalString.length() + 6, spannableString.length() - 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

}
